﻿using System;
using System.Collections.Generic;

namespace 新语法
{

    #region 运行时类型转换
    class Animal
    {
        public void Eat() => System.Console.WriteLine("Eating.");
        public override string ToString() => "I am an animal.";
    }

    class Reptile : Animal
    {
        public override string ToString() => "I am an Reptile.";
    }

    class Mammal : Animal 
    {
        public override string ToString() => "I am an Mammal.";
    }
    #endregion

    class Program
    {
        static void Print(object x)
        {
            Console.WriteLine(x);
        }

        static void Pause()
        {
            Console.ReadKey();
        }

        static void Main(string[] args)
        {
            var a = 23;
            Print(a);
            Console.WriteLine("Hello World!");

            // 动态类型转换
            Test(new Mammal());
            Test(new Reptile());

            ForTest();
            Pause(); 
        }

        #region 循环迭代语句
        static void ForTest()
        {
            for (int i = 0; i < 3; i++)
            {
                Console.Write(i);
            }

            var fibNumbers = new List<int> { 0, 1, 1, 2, 3, 5, 8, 13 };
            foreach (int element in fibNumbers)
            {
                Console.Write($"{element} ");
            }

            Span<int> numbers = new int[] { 3, 14, 15, 92, 6 };
            foreach (int number in numbers)
            {
                Console.Write($"{number} ");
            }
        }
        #endregion


        static void Test(Animal a)
        {
            Print(a);
        }
    }
}
